package cn.lg.soar.system.biz.modules.auth.controller;

import cn.lg.soar.common.model.HttpResult;
import cn.lg.soar.core.annotations.DataScope;
import cn.lg.soar.system.api.constant.ModuleConst;
import cn.lg.soar.system.api.enums.RoleTypeEnum;
import cn.lg.soar.system.biz.modules.auth.model.RoleSelectorDTO;
import cn.lg.soar.system.biz.modules.auth.service.RoleSelectorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Validated
@Tag(name = "角色选择器")
@RestController
@RequestMapping(ModuleConst.MODULE_NAME + "/role-selector")
public class RoleSelectorController {

    @Autowired
    private RoleSelectorService roleSelectorService;

    @Operation(summary = "根据id")
    @GetMapping(value = "ids")
    public HttpResult<List<RoleSelectorDTO>> ids(@RequestParam(name = "ids") List<Long> ids){
        return HttpResult.data(roleSelectorService.ids(ids));
    }

    @DataScope(code = "role", name = "角色")
    @Operation(summary = "关键字搜索")
    @GetMapping(value = "query")
    public HttpResult<List<RoleSelectorDTO>> query(@RequestParam(name = "keyword") String keyword, @RequestParam(name = "types", required = false) RoleTypeEnum[] types){
        return HttpResult.data(roleSelectorService.query(keyword, types));
    }

    @DataScope(code = "role", name = "角色")
    @Operation(summary = "根据角色")
    @GetMapping(value = "role")
    public HttpResult<List<RoleSelectorDTO>> role(@RequestParam(name = "parentId") Long parentId){
        return HttpResult.data(roleSelectorService.role(parentId));
    }

}
